package com.study.base.concurrent;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Description:
 * User: 27010
 * DateTime: 2018/3/8 11:30
 */
public class ReadWriteLock {
    public static void main(String[] args) {
        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
        lock.writeLock().lock();
        System.out.println("write");

        for (int i = 0; i < 100; i++) {
            lock.readLock().lock();
            System.out.println("read" + i);
        }


        lock.readLock().lock();
        System.out.println("read");

        lock.writeLock().lock();
        System.out.println("write");
        lock.writeLock().unlock();

        lock.readLock().unlock();

        for (int i = 0; i < 100; i++) {
            lock.readLock().unlock();
        }


        lock.writeLock().unlock();

    }
}
